package
{
	import flash.events.Event;
	
	public class PhotoWalletController
	{
		
		private var _photoModel:PhotoWalletModel;
		private var _photoView:PhotoWalletView;
		
		public function PhotoWalletController( photoModel:PhotoWalletModel, photoView:PhotoWalletView ) {
			
			_photoModel = photoModel;
			
			_photoView = photoView;
			
			addListeners();			
			
		}
		
		private function addListeners():void {
			
			// Add listeners to check for user activity on the buttons in the view
			_photoView.addEventListener( PhotoWalletView.NEXT_CLICKED, goToNextPhoto );
			_photoView.addEventListener( PhotoWalletView.PREVIOUS_CLICKED, goToPreviousPhoto );
			_photoView.addEventListener( PhotoWalletView.PLAY_CLICKED, playOrPause );
			
		}
		
		// These next two methods are essentially triggers for functionality in the model
		private function goToNextPhoto( e:Event ):void {
			
			_photoModel.goToNextPhoto();
			
		}
		
		private function goToPreviousPhoto( e:Event ):void {
			
			_photoModel.goToPreviousPhoto();
			
		}
		
		private function playOrPause( e:Event ):void {
			
			if( _photoModel.getSlideShow() ) {
				
				_photoModel.stopSlideShow();
				
			} else {
				
				_photoModel.startSlideShow();
			}
			
		}
		
	}
}
